package alchemist.model;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

@PersistenceCapable( identityType = IdentityType.APPLICATION, detachable = "true" )
public class Progress
{
    @PrimaryKey
    @Persistent
    private String                   userId;
    @Persistent
    private Set< DiscoveredElement > discovered = new HashSet< DiscoveredElement >();

    public Progress()
    {
    }

    public String getUserId()
    {
        return userId;
    }

    public void setUserId( String userId )
    {
        this.userId = userId;
    }

    public Set< DiscoveredElement > getDiscovered() 
    {
        return discovered;
    }

    public void setDiscovered( Set< DiscoveredElement > discovered ) 
    {
        this.discovered = discovered;
    }
    
    public void addDiscovered( Set< String > elementIds )
    {
        for ( String elementId : elementIds ) 
        {
            this.addDiscovered( elementId );
        }
    }

    public void addDiscovered( String elementId ) 
    {
        this.getDiscovered().add( new DiscoveredElement( elementId , new Date() ) );
    }
    
    public Set< String > getElements()
    {
        final Set< String > result = new HashSet< String >();
        for ( DiscoveredElement element : this.getDiscovered() ) 
        {
            result.add( element.getElementId() );
        }
        return result;
    }

}
